const {
  addClass,
  addOClass,
  getClassList,
  delClass,
  delSomeClass,
  updateClass,
} = require("../controller/class");
const { SuccessModel, ErrorModel } = require("../model/resModel");
var express = require("express");
var router = express.Router();
const jwt = require("jsonwebtoken");
const loginCheck = require("../middleware/loginCheck");
const authCheck = require("../middleware/authCheck");
/* GET users listing. */

router.post("/add_class", (req, res, next) => {
  const result = addClass(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("添加失败"));
    }
  });
});
router.post("/add_o_class", (req, res, next) => {
  const result = addOClass(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("添加失败"));
    }
  });
});
router.get("/get_class", function (req, res, next) {
  const result = getClassList();
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/del_class", (req, res, next) => {
  const result = delClass(req.query.id);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel(val));
    } else {
      res.json(new ErrorModel("删除失败"));
    }
  });
});
router.post("/del_s_class", function (req, res, next) {
  const result = delSomeClass(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("删除失败"));
    }
  });
});
router.post("/update_class", function (req, res, next) {
  const result = updateClass(req.query.id, req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
module.exports = router;
